package com.wjk.cms.util.sms;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SmsUtil {

    public static Integer sendVerificationCode(String phone, String code, String channel) {
        String signName = getSenderName(channel);
        int responseCode = 0;
        try {
            String response = AliyunSmsUtil.sendSms(signName, phone, code);
            log.info("发送验证码至" + phone + " - " + code + "\n" + response);
            responseCode = JSONObject.parseObject(response).getString("Code").equals("OK") ? 0 : 1;
        } catch (Exception e) {
            responseCode = 1;
        }
        return responseCode;
    }

    public static String getSenderName(String channel) {
        if ("mall".equals(channel)) {
            return "航旅通";
        }
        return "航旅通";
    }

    public static void main(String[] arg) throws Exception {
        Integer integer = SmsUtil.sendVerificationCode("15562666861", "6666", null);
        System.out.println(integer);
    }

}
